package com.example.demo.Enum;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum ProCateRelEnum {
    PUT_ON(0,"上架"),
    PUT_OFF(1,"下架");
    @EnumValue

    private final int code;
    @JsonValue
    private final String description;
    @JsonCreator
    public static ProCateRelEnum fromCode(int code) throws RuntimeException {
        for (ProCateRelEnum proCateRelEnum : ProCateRelEnum.values()) {
            if (proCateRelEnum.code == code) {
                return proCateRelEnum;
            }
        }
        throw new RuntimeException("无法将枚举值转化为商品状态对象");
    }
    @JsonCreator
    public static ProCateRelEnum fromString(String value) {
        for (ProCateRelEnum proCateRelEnum : ProCateRelEnum.values()) {
            if (proCateRelEnum.name().equals(value)) {
                return proCateRelEnum;
            }
        }
        throw new IllegalArgumentException("无效的产品状态: " + value);
    }
}
